import request from '../flow-request'
import { ResponseData } from '@/types/api/public'
import { TableList, EditData } from '@/types/api/flowDeploy'
import { AxiosResponse } from 'axios'

type ConfigType<T = ResponseData> = Promise<AxiosResponse<T>>

export const getData = (params: any): ConfigType<TableList> => {
    params.pageable = {};
    params.pageable.PageNo = params.current;
    params.pageable.PageSize = params.pageSize;
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/admin/tasks/GetAllTasks',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

// 任务办理
export const completeTask = (params: any): ConfigType => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/complete',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json'
        }
    })
}

// 任务退回
export const returnTo = (params: any): ConfigType => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/returnto',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json'
        }
    })
}

//获取历史任务
export const getHistorySingleTaskLists = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/history/process-instances/tasks/getHistorySingleTaskLists',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

export const getHistoryActivityLists = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/history/process-instances/tasks/getHistoryActivityLists',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//流程挂起
export const suspendTask = (processInstanceId: any): ConfigType<TableList> => {

    return request({
        url: '/Api/v1/workflow/process-instances/' + processInstanceId + '/suspend',
        method: 'get',
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//退签
export const releaseClaim = (taskId: any): ConfigType<TableList> => {
    return request({
        url: '/Api/v1/workflow/tasks/' + taskId + '/release',
        method: 'post',
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//同意
export const approvaledTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/approvaled',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//拒绝
export const rejectTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/reject',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//转办任务
export const transferTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/transfer',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}
//任务终止
export const terminateTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({    
        url: '/Api/v1/workflow/tasks/terminate',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//删除任务
export const removeTask = (taskId: any): ConfigType<TableList> => {
    return request({
        url: '/Api/v1/workflow/tasks/' + taskId + '/remove',
        method: 'post',
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//追加办理人
export const appendAssigneeTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/append',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}

//下一步节点信息
export const getNextNodeInfo =(params:any):ConfigType<string> =>{  
    return request({
        url:'/Api/v1/process-definitions/meta/next-process-definitions/meta-data',
        params,
        method:'get'
    })
}

export const jumpTask = (params: any): ConfigType<TableList> => {
    const data = JSON.stringify(params);
    return request({
        url: '/Api/v1/workflow/tasks/jumptask1',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/json-patch+json'
        }
    })
}